{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "let inputBox = (s: string): string => {\n",
    "    let r = \"\"\n",
    "    for (let i=0; i < s.length; i++) {\n",
    "        let c = s[i]\n",
    "        if (c == \"#\") {\n",
    "            if (r.length > 0) {\n",
    "                r = r.slice(0, r.length-1)\n",
    "            }\n",
    "        } else {\n",
    "            r += c\n",
    "        }\n",
    "    }\n",
    "    return r\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "function backspaceCompare(S: string, T: string): boolean {\n",
    "    return inputBox(S) == inputBox(T)\n",
    "};"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/backspace-string-compare/\n",
    "\n",
    "\n",
    "\n",
    "Runtime: 100 ms, faster than 5.56% of TypeScript online submissions for Backspace String Compare.\n",
    "Memory Usage: 40.6 MB, less than 22.22% of TypeScript online submissions for Backspace String Compare.\n",
    "\n",
    "\n",
    "\n",
    "```typescript\n",
    "let inputBox = (s: string): string => {\n",
    "    let r = \"\"\n",
    "    for (let i=0; i < s.length; i++) {\n",
    "        let c = s[i]\n",
    "        if (c == \"#\") {\n",
    "            if (r.length > 0) {\n",
    "                r = r.slice(0, r.length-1)\n",
    "            }\n",
    "        } else {\n",
    "            r += c\n",
    "        }\n",
    "    }\n",
    "    return r\n",
    "}\n",
    "\n",
    "function backspaceCompare(S: string, T: string): boolean {\n",
    "    return inputBox(S) == inputBox(T)\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "TypeScript",
   "language": "typescript",
   "name": "tslab"
  },
  "language_info": {
   "codemirror_mode": {
    "mode": "typescript",
    "name": "javascript",
    "typescript": true
   },
   "file_extension": ".ts",
   "mimetype": "text/typescript",
   "name": "typescript",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
